// 测试 XLayer 合约的创建费用要求
const { ethers } = require('ethers');

async function testContractFeeRequirement() {
  const provider = new ethers.JsonRpcProvider('https://testrpc.xlayer.tech/terigon');
  const contractAddress = '0xd9B7BDD6DbC80DaEc00fB0a6c920eA50C1eDF017';
  
  const contract = new ethers.Contract(
    contractAddress,
    [
      'function createTokenLaunch(string memory _name, string memory _symbol, string memory _description, string memory _website, string memory _telegram, string memory _twitter, uint256 _targetAmount) external payable'
    ],
    provider
  );

  const targetAmountWei = ethers.parseEther('1');
  
  try {
    // 尝试估算不同费用的gas消耗
    console.log('Testing different fee amounts...');
    
    // 测试 0.01 OKB
    try {
      const gasEstimate1 = await contract.createTokenLaunch.estimateGas(
        'TestToken',
        'TEST',
        'Description',
        '',
        '',
        '',
        targetAmountWei,
        { value: ethers.parseEther('0.01') }
      );
      console.log('✅ 0.01 OKB: Gas estimate =', gasEstimate1.toString());
    } catch (error) {
      console.log('❌ 0.01 OKB: Failed -', error.message);
    }
    
    // 测试 0.02 OKB
    try {
      const gasEstimate2 = await contract.createTokenLaunch.estimateGas(
        'TestToken',
        'TEST',
        'Description',
        '',
        '',
        '',
        targetAmountWei,
        { value: ethers.parseEther('0.02') }
      );
      console.log('✅ 0.02 OKB: Gas estimate =', gasEstimate2.toString());
    } catch (error) {
      console.log('❌ 0.02 OKB: Failed -', error.message);
    }
    
    // 测试 0.005 OKB (更少)
    try {
      const gasEstimate3 = await contract.createTokenLaunch.estimateGas(
        'TestToken',
        'TEST',
        'Description',
        '',
        '',
        '',
        targetAmountWei,
        { value: ethers.parseEther('0.005') }
      );
      console.log('✅ 0.005 OKB: Gas estimate =', gasEstimate3.toString());
    } catch (error) {
      console.log('❌ 0.005 OKB: Failed -', error.message);
    }
    
  } catch (error) {
    console.error('Error testing contract:', error);
  }
}

testContractFeeRequirement();
